﻿<%namespace YouHP.Model%>
<%namespace YouHP.Utility%>
<%template _header%>

<script language="javascript" src="/support/editor/script_common.js"></script>

<script language="javascript" src="/support/editor/editor_function.js"></script>

<div class="layout-cols2">
    <%csharp%>if( IsPost){
    <%/csharp%>
    <%template _MsgBox%>
    <%csharp%>
    } else {
    <%/csharp%>
    <div class="box">
        <div class="caption">
            发表帖子
        </div>
        <div class="content" style="text-align: center;">
            <div style="margin: 0 auto;">
                <form id="topicform" name="topicform" method="post" action="" enctype="multipart/form-data">
                <input type="hidden" name="gid" value="{GroupData.Id}">
                <table class="editboxstyle">
                    <tbody>
                        <tr>
                            <td>
                                标题：
                            </td>
                            <td>
                                <input type="text" name="ttitle" size="60" class="inputstyle" onChange="relatekwtitle();"/>
                                &nbsp;&nbsp;<span>(标题长度必须在{Config.TitleMinSize}-{Config.TitleMaxSize}之间)</span>
                                &nbsp;&nbsp;分类：
                                <select id="TopicSort" name="TopicSort">
                                        <option value="-1" selected>分类选中的帖子</option>
                                        <option value="">普通帖</option>
                                        <%csharp%>foreach(string item in TopicSortList) { <%/csharp%>
                                        <option value="{item}">{item}</option>
                                        <%csharp%>}<%/csharp%>
                                </select>
                            </td>
                        </tr>
                        <tr valign="top">
                            <td>
                                内容：
                            </td>
                            <td>
                                <textarea id="uchome-ttHtmlEditor" name="tbody" cols="90" rows="15" style="display: none"></textarea>
                                <iframe src="/support/editor/editor.htm" name="uchome-ifrHtmlEditor" id="uchome-ifrHtmlEditor"
                                    scrolling="no" border="0" frameborder="0" style="width: 641px; border: 1px solid #C5C5C5;"
                                    height="300"></iframe>
                                <p>
                                    内容长度必须在{Config.TopicMinSize}-{Config.TopicMaxSize}之间</p>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                附件：
                            </td>
                            <td>
                                <input name="file" id="file" type="file" size="40" class="colorblue" onfocus="this.className='colorfocus';"
                                    onblur="this.className='colorblue';" />
                                <span>类型限定（RAR、ZIP、TXT、JPG、PNG、GIF）文件最大为1M</span>
                            </td>
                        </tr>
                        <tr>
					     <td>标签：</td>
					     <td><input type="text" name="tags" id="tags" value="" style="margin-bottom:-1px;" size="55" />&nbsp;<input type="button" onclick="relatekwbody();" value="自动获取"/>  (用空格隔开多个标签，最多可填写 5 个)</td>
                        </tr>
                        <tr>
                            <td>
                            </td>
                            <td align="right">
                                <span id="submitButton" onmouseout="this.className='new_sbt'" onmouseover="this.className='new_sbt_h'"
                                    onclick="javascript:edit_save();CheckForm();" class="new_sbt">提交</span>
                            </td>
                        </tr>
                    </tbody>
                </table>
                </form>

                <script type="text/javascript">
	                function CheckForm()
	                {
	                    if(_$('TopicSort').value == -1)
	                    {
	                       alert("请选择帖子分类！");
	                       return;
	                     }
	                     _$('submitButton').disabled = true;
	                     _$('topicform').submit();
	                }
                    function createXMLHttp() {
                        if(window.XMLHttpRequest){
                            return new XMLHttpRequest();
                        } else if(window.ActiveXObject){
                            return new ActiveXObject("Microsoft.XMLHTTP");
                        } 
                        throw new Error("XMLHttp object could be created.");
                    }
                    function _sendRequest(url,func,isxml,postdata)
                    {
                        var xhr=createXMLHttp();
                        if(!postdata)postdata=null;
                        xhr.open(postdata?"POST":"GET",url,true);
                        if (postdata)
                        {
                            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                        }
                        if(func){
		                    xhr.onreadystatechange=function(){
			                    if(xhr.readyState==4){
				                    func(isxml&&xhr.responseXML?xhr.responseXML:xhr.responseText)
			                    }
		                    }
	                    }
                        if (postdata === true)
                        {
                            postdata = '';
                        }
                        xhr.send(postdata)
                    }
                    function encodeURL(a) {
                        return window.encodeURIComponent?encodeURIComponent(a):escape(a)
                    }
                    function relatekw(title, message) {
//                        if (typeof title=='undefined')
//                        {
//                            title = _$('ttitle').value;
//                        }
//                        if (typeof message=='undefined')
//                        {
//                            //edit_save();
//                            message = _$('uchome-ttHtmlEditor').value;
//                        }	
                        title = encodeURL(title);
                        message = message.replace(/&/ig, '', message);
                        message = encodeURL(message);
                        _sendRequest('/pages/alpha/ajax/AjaxPage.aspx?t=relatekw', relatedkw,true, 'titleenc=' + title + '&contentenc=' + message);
                    }
                    function relatekwtitle(title){
                        if(typeof title=='undefined')
                        {
                            title = _$('ttitle').value;
                        }
                        relatekw(title,'');
                    }
                    function relatekwbody(message){
                        if(typeof message=='undefined')
                        {
                            edit_save();
                            message = _$('uchome-ttHtmlEditor').value; 
                        }
                        relatekw('',message);
                    }
                    function relatedkw(obj) {
	                    if (obj == null || typeof(obj) != "object" || obj.firstChild == null)
	                    {
		                    return;
	                    }
	                    if (is_ie)
	                    {
		                    //evalscript(obj.text);
		                    _$('tags').value = obj.text + _$('tags').value;
		                    _$('tags').value = getTags();
	                    }
	                    else
	                    {
		                    evalscript(obj.firstChild.firstChild.nodeValue);
	                    }
                    }
                    var evalscripts = new Array();
                    function evalscript(s) {

	                    if(s.indexOf('<script') == -1) return s;

	                    var p = /<script[^\>]*src=\"([^\x00]+?)\"[^\>]*( reload=\"1\")?><\/script>/ig;

	                    var arr = new Array();

	                    while(arr = p.exec(s)) appendscript(arr[1], '', arr[2]);

	                    p = /<script[^\>]*( reload=\"1\")?>([^\x00]+?)<\/script>/ig;

	                    while(arr = p.exec(s)) appendscript('', arr[2], arr[1]);

	                    return s;

                    }

                    function appendscript(src, text, reload) {
	                    var id = hash(src + text);
	                    if(!reload && in_array(id, evalscripts)) return;

	                    if(reload && _$(id)) {

		                    _$(id).parentNode.removeChild(_$(id));

	                    }

	                    evalscripts.push(id);

	                    var scriptNode = document.createElement("script");

	                    scriptNode.type = "text/javascript";

	                    scriptNode.id = id;

	                    try {

		                    if(src) {

			                    scriptNode.src = src;

		                    } else if(text){

			                    scriptNode.text = text;

		                    }

		                    _$('append_parent').appendChild(scriptNode);

	                    } catch(e) {}

                    }

                    function hash(string, length) {

	                    var length = length ? length : 32;

	                    var start = 0;

	                    var i = 0;

	                    var result = '';

	                    filllen = length - string.length % length;

	                    for(i = 0; i < filllen; i++){

		                    string += "0";

	                    }

	                    while(start < string.length) {

		                    result = stringxor(result, string.substr(start, length));

		                    start += length;

	                    }

	                    return result;

                    }

                    function stringxor(s1, s2) {

	                    var s = '';

	                    var hash = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

	                    var max = Math.max(s1.length, s2.length);

	                    for(var i=0; i<max; i++) {

		                    var k = s1.charCodeAt(i) ^ s2.charCodeAt(i);

		                    s += hash.charAt(k % 52);

	                    }

	                    return s;
                    }
                    function getTags(){
                            var oldValue = new Array();
                            var newValue = new Array();
                            var newStr="";
                            var str = _$('tags').value;
                            if(str == "")
                            {
                               return newStr;
                            } 
                            oldValue=str.split(" "); 
                            if(oldValue.length<2)
                            {
                               return newStr; 
                            } 

                            for(t=0;t<oldValue.length;t++)
                            { 
                                if(!compare(oldValue[t],newValue))
                                { 
                                    newValue.push(oldValue[t]); 
                                    newStr += oldValue[t];
                                    newStr +=" ";
                                } 
                            } 
                            return newStr;
                        } 
                        /* 
                          方法：比对字符串是否存在于数组 
                          参数1：str 需要比对的字符串 
                          参数2：arrayValue 比对的数组 
                        */ 
                        function compare(str,arrayValue){ 
                        //数组为空 
                            if(arrayValue.length<0)
                            { 
                                return false; 
                            } 
                            //判断str是否存在于数组 
                            for(i=0;i<arrayValue.length;i++)
                            { 
                               if(str==arrayValue[i])
                               { 
                                  return true; 
                               } 
                            } 
                            return false; 
                        } 
                </script>

            </div>
        </div>
    </div>
</div>
<%csharp%>
}
<%/csharp%>

<%template _footer%>